package com.jinduplan.planmanager.mvp.presenter

import com.cxz.kotlin.baselibs.ext.ss
import com.cxz.kotlin.baselibs.ext.sss
import com.cxz.kotlin.baselibs.http.HttpStatus
import com.cxz.kotlin.baselibs.http.exception.ExceptionHandle
import com.cxz.kotlin.baselibs.mvp.BasePresenter
import com.cxz.kotlin.baselibs.rx.SchedulerUtils
import com.cxz.kotlin.baselibs.utils.GsonHelper
import com.cxz.kotlin.baselibs.utils.LogUtil
import com.jinduplan.planmanager.mvp.contract.MainContract
import com.jinduplan.planmanager.mvp.contract.MainFragmentContract
import com.jinduplan.planmanager.mvp.model.MainFragmentModel
import com.jinduplan.planmanager.mvp.model.MainModel

/**
 * @author admin
 * @date 2018/11/20
 * @desc
 */
class MainFragmentPresenter : BasePresenter<MainFragmentContract.Model, MainFragmentContract.View>(), MainFragmentContract.Presenter {

    override fun createModel(): MainFragmentContract.Model = MainFragmentModel()

    override fun getTips() {
        mModel?.getTips()?.ss(mModel,mView,onSuccess = {
            mView?.showTips("")
        })
    }

    override fun getWeatherIp() {
        mModel?.getWeatherIp()?.ss(mModel,mView,onSuccess = {
            val code = if (it.data.content.address_detail.city_code.isNullOrEmpty()) it.data.content.address_detail.adcode else it.data.content.address_detail.adcode
            mView?.setWeatherIpAdCode(code)
        })
    }

    override fun getWeather(adcode: String) {
        mModel?.getWeather(adcode)?.ss(mModel,mView,onSuccess = {
            mView?.setWeatherData(it.data)
        })
    }


}